package com.qfedu.yanglao20admin.companion.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.common.param.PageParam;
import com.qfedu.yanglao20.entity.companion.Companion;
import com.qfedu.yanglao20admin.companion.param.CompanionParam;
import com.qfedu.yanglao20admin.companion.service.CompanionService;
import com.qfedu.yanglao20admin.companion.vo.CompanionCommonVO;
import com.qfedu.yanglao20admin.companion.vo.CompanionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(tags = "陪护员列表")
@RestController
@RequestMapping("/companion")
public class CompanionController {

    @Resource
    private CompanionService companionService;

    @LogInfo
    @ApiOperation(value = "分页展示陪护员信息", notes = "分页展示陪护员信息")
    @GetMapping("/list")
    public CommonResult<PageParam> page(CompanionParam param) {
        Page<CompanionVO> companion = companionService.pageCompanion(param);
        return CommonResult.success(companion);
    }

    @LogInfo
    @ApiOperation(value = "添加陪护员信息", notes = "添加陪护员信息")
    @PostMapping("/add")
    public CommonResult<CompanionCommonVO> addCompanion(CompanionCommonVO companionCommonVO) {
        companionService.addCompanion(companionCommonVO);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询陪护员信息", notes = "根据id查询陪护员信息")
    @GetMapping("/query")
    public CommonResult queryCompanion(@RequestParam @ApiParam("陪护员id") Integer id) {
        Companion companion = companionService.queryCompanion(id);
        return CommonResult.success(companion);
    }

    @LogInfo
    @ApiOperation(value = "修改陪护员信息", notes = "修改陪护员信息")
    @PostMapping("/update")
    public CommonResult<CompanionCommonVO> updateCompanion(CompanionCommonVO companionCommonVO) {
        companionService.addCompanion(companionCommonVO);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "删除陪护员信息", notes = "删除陪护员信息")
    @PostMapping("/delete")
    public CommonResult<Companion> deleteCompanion(@RequestParam @ApiParam("陪护员id") Integer id) {
        companionService.deleteById(id);
        return CommonResult.success();
    }
}
















